import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
import { GameManager, GameStatus } from './GameManager';

@ccclass('MoveBackground')
export class MoveBackground extends Component {
  @property({ type: Node })
  Background001: Node
  @property({ type: Node })
  Background002: Node
  start() {

  }

  update(deltaTime: number) {
    if (GameManager.status === GameStatus.GamePlay) {
      const MoveDistance = GameManager.MoveSpeed * deltaTime
      this.Background001.setPosition(this.Background001.position.x - MoveDistance, this.Background001.position.y)
      this.Background002.setPosition(this.Background002.position.x - MoveDistance, this.Background002.position.y)
      if (this.Background001.position.x <= -720) {
        this.Background001.setPosition(this.Background002.position.x + 720, this.Background001.position.y)
      }
      if (this.Background002.position.x <= -720) {
        this.Background002.setPosition(this.Background001.position.x + 720, this.Background002.position.y)
      }
    }
  }
}


